package com.zj.cman.modules.articles.service;

import com.zj.cman.modules.articles.dao.ArticleMapper;
import com.zj.cman.modules.articles.dao.CategoryMapper;
import com.zj.cman.modules.articles.dao.TagMapper;
import com.zj.cman.modules.articles.entity.Article;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Set;

@Service
public class ArticleService {

    @Autowired
    private ArticleMapper articleMapper;

    @Autowired
    private CategoryMapper categoryMapper;

    @Autowired
    private TagMapper tagMapper;

    @Transactional
    public void saveArticleWithCategoriesAndTags(Article article, Set<Long> categoryIds, Set<Long> tagIds) {
        articleMapper.insert(article);

        if (categoryIds != null && !categoryIds.isEmpty()) {
            // 插入 article_categories 关系
            // 这里需要你自己实现插入逻辑，比如通过批量插入的方式
        }

        if (tagIds != null && !tagIds.isEmpty()) {
            // 插入 article_tags 关系
            // 这里需要你自己实现插入逻辑，比如通过批量插入的方式
        }
    }
}
